package cn.xopencode.appletweb.controller.score.demand;

import cn.xopencode.common.framework.vo.CommonResult;
import cn.xopencode.common.framework.vo.PageResult;
import cn.xopencode.score.api.rpc.ScoreRpc;
import cn.xopencode.score.api.rpc.demand.dto.ScoreDetailsRespDTO;
import cn.xopencode.score.api.rpc.demand.dto.ScoreReqDTO;
import cn.xopencode.score.api.rpc.demand.dto.ScoreRespDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

@Api(tags = "积分查询情况 API")
@RestController
@RequestMapping("/demand")
@Validated
public class ScoreDemandController {
    @DubboReference(version = "${dubbo.consumer.ScoreRpc.version}")
    private ScoreRpc scoreRpc;

    @ApiOperation(value = "获取分数列表数据")
    @GetMapping("/findAll")
    public CommonResult<List<ScoreRespDTO>> findAllScore() {

        CommonResult<List<ScoreRespDTO>> scoreList = scoreRpc.getScoreList();
        System.out.println(scoreList);
        return scoreList;
    }

    @ApiOperation(value = "获取个人积分详细数据")
    @GetMapping("/findScoreDetails")
    public CommonResult<ScoreDetailsRespDTO> findScoreDetails(@RequestParam(value="empId",required = false)String empId,
                                                              @RequestParam(value="updateTime",required = false)String updateTime,
                                                              @RequestParam(value="page",defaultValue = "1")Integer pageNo,
                                                              @RequestParam(value="pageSize",defaultValue = "5")Integer pageSize) {
//        ScoreReqDTO scoreReqDTO = new ScoreReqDTO();
//        scoreReqDTO.setId(empId);
//        scoreReqDTO.setUpdateTime(updateTime);
//        scoreReqDTO.setPageNo(pageNo);
//        scoreReqDTO.setPageSize(pageSize);
        CommonResult<ScoreDetailsRespDTO> scoreDetails = scoreRpc.getScoreDetails(empId);
//        System.out.println("scoreDetails:"+scoreDetails);
        return scoreDetails;
    }

    @ApiOperation(value = "根据修改日期获取分数列表数据")
    @GetMapping("/findScoreByDate/{date}")
    public CommonResult<List<ScoreRespDTO>> findScoreFromDate(@PathVariable(value="date",required = false)String date) {
/*        String result = recordTestRpc.test();
        System.out.println(result);*/
//        CommonResult<String> a = scoreRpc.getScoreDetails(new ScoreReqDTO());
        ScoreReqDTO scoreReqDTO = new ScoreReqDTO();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
        Date parseDate = null;
        try {
//            parseDate = simpleDateFormat.parse(date);
            parseDate = simpleDateFormat.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        scoreReqDTO.setUpdateTime(parseDate);
        scoreReqDTO.setPageNo(1);
        scoreReqDTO.setPageSize(5);
        CommonResult<List<ScoreRespDTO>> dateScoreList = scoreRpc.getDateScoreList(scoreReqDTO);
        System.out.println("dateScoreList:"+dateScoreList);
        return dateScoreList;
    }

}
